Context. Linear rotor molecules such as CO, HCO+ and HCN are important probes of star-forming gas. For these species, temperatures of < ∼ 50 K are sufficient to produce emission lines that are observable from the ground at (sub)millimeter wavelengths. Molecular gas in the environment of massive protostellar objects, however, is known to reach temperatures of several hundred K. To probe this, space-based far-infrared observations are required. Aims. We aim to reveal the gas energetics in the circumstellar environment of the prototypical high-mass protostellar object AFGL 2591. Methods. Rotational spectral line signatures of CO species, HCO + , CS, HCN and HNC from a 490-1240 GHz survey with Herschel/HIFI, complemented by ground-based JCMT and IRAM 30 m spectra, cover transitions in the energy range (E up /k) between 5 K and ∼300 K. Selected frequency settings in the highest frequency HIFI bands (up to 1850 GHz) extend this range to 750 K for 12 C 16 O. The resolved spectral line profiles are used to separate and study various kinematic components. Observed line intensities are compared with a numerical model that calculates excitation balance and radiative transfer based on spherical geometry. Results. The line profiles show two emission components, the widest and bluest of which is attributed to an approaching outflow and the other to the envelope. We find evidence for progressively more redshifted and wider line profiles from the envelope gas with increasing energy level. This trend is qualitatively explained by residual outflow contribution picked up in the systematically decreasing beam size. Integrated line intensities for each species decrease as E up /k increases from < ∼ 50 to ∼700 K. The H 2 density and temperature of the outflow gas are constrained to ∼10 5 -10 6 cm −3 and 60-200 K. In addition, we derive a temperature between 9 and 17 K and N(H 2 ) ∼ 3 × 10 21 cm −2 for a known foreground cloud seen in absorption, and N(H 2 ) < ∼ 10 19 cm −2 for a second foreground component. Conclusions. Our spherical envelope model systematically underproduces observed line emission at E up /k > ∼ 150 K for all species. This indicates that warm gas should be added to the model and that the model's geometry should provide low optical depth pathways for line emission from this warm gas to escape, for example in the form of UV heated outflow cavity walls viewed at a favorable inclination angle. Physical and chemical conditions derived for the outflow gas are similar to those in the protostellar envelope, possibly indicating that the modest velocity ( < ∼ 10 km s −1 ) outflow component consists of recently swept-up gas.