  Aims. Young stars interact vigorously with their surroundings, as evident
from the highly rotationally excited CO (up to Eup=4000 K) and H2O emission (up
to 600 K) detected by the Herschel Space Observatory in embedded low-mass
protostars. Our aim is to construct a model that reproduces the observations
quantitatively, to investigate the origin of the emission, and to use the lines
as probes of the various heating mechanisms.
  Methods. The model consists of a spherical envelope with a bipolar outflow
cavity. Three heating mechanisms are considered: passive heating by the
protostellar luminosity, UV irradiation of the outflow cavity walls, and C-type
shocks along the cavity walls. Line fluxes are calculated for CO and H2O and
compared to Herschel data and complementary ground-based data for the
protostars NGC1333 IRAS2A, HH 46 and DK Cha. The three sources are selected to
span a range of evolutionary phases and physical characteristics.
  Results. The passively heated gas in the envelope accounts for 3-10% of the
CO luminosity summed over all rotational lines up to J=40-39; it is best probed
by low-J CO isotopologue lines such as C18O 2-1 and 3-2. The UV-heated gas and
the C-type shocks, probed by 12CO 10-9 and higher-J lines, contribute 20-80%
each. The model fits show a tentative evolutionary trend: the CO emission is
dominated by shocks in the youngest source and by UV-heated gas in the oldest
one. This trend is mainly driven by the lower envelope density in more evolved
sources. The total H2O line luminosity in all cases is dominated by shocks
(>99%). The exact percentages for both species are uncertain by at least a
factor of 2 due to uncertainties in the gas temperature as function of the
incident UV flux. However, on a qualitative level, both UV-heated gas and
C-type shocks are needed to reproduce the emission in far-infrared rotational
lines of CO and H2O.
