The physical structure of the envelopes around a sample of 14 massive young stars is investigated using maps and spectra in submillimeter continuum and lines of C17O, CS, C34S, and H2CO. Nine of the sources are highly embedded luminous (103-105 L☉) young stellar objects that are bright near-infrared sources but weak in radio continuum; the other objects are similar but not bright in the near-infrared and contain "hot-core"-type objects and/or ultracompact H II regions. The data are used to constrain the temperature and density structure of the circumstellar envelopes on 102-105 AU scales, to investigate the relation between the different objects, and to search for evolutionary effects. The total column densities and the temperature profiles are obtained by fitting self-consistent dust models to submillimeter photometry. The calculated temperatures range from 300 to 1000 K at ~102 AU and from 10 to 30 K at ~105 AU from the star. Visual extinctions are a few hundred to a few thousand magnitudes, assuming a grain opacity at 1300 μm of ≈1 cm-2 g-1 of dust, as derived earlier for one of our sources. The mid-infrared data are consistent with a 30% decrease of the opacity at higher temperatures, caused by the evaporation of the ice mantles. The CS, C34S, and H2CO data as well as the submillimeter dust emission maps indicate density gradients n ∝ r-α. Assuming a constant CS abundance throughout the envelope, values of α = 1.0-1.5 are found, which is significantly flatter than the α = 2.0 ± 0.3 generally found for low-mass objects. This flattening may indicate that in massive young stellar objects, nonthermal pressure is more important for the support against gravitational collapse, while thermal pressure dominates for low-mass sources. We find α = 2 for two hot-core-type sources but regard this as an upper limit since, in these objects, the CS abundance may be enhanced in the warm gas close to the star. The assumption of spherical symmetry is tested by modeling infrared absorption line data of 13CO, CS emission-line profiles and near-infrared continuum. There is a distinct, but small deviation from spherical symmetry: the data are consistent with a decrease of the optical depth by a factor of ≈3 in the central ≲10''. The homogeneity of the envelopes is verified by the good agreement of the total masses in the power-law models with the virial masses. Modeling of C17O emission shows that ≈40%-90% of the CO is frozen out onto the dust. The CO abundances show a clear correlation with temperature, as expected if the abundance is controlled by freeze-out and thermal desorption. The CS abundance is 3 × 10-9 on average, ranging from (4-8) × 10-10 in the cold source GL 7009S to (1-2) × 10-8 in the two hot-core-type sources. Dense outflowing gas is seen in the CS and H2CO line wings; the predominance of blueshifted emission suggests the presence of dense, optically thick material within 10'' of the center. Interferometric continuum observations at 1300-3500 μm show compact emission, probably from a 03 diameter, optically thick dust component, such as a dense shell or a disk. The emission is a factor of 10-100 stronger than expected for the envelopes seen in the single-dish data, so that this component may be opaque enough to explain the asymmetric CS and H2CO line profiles. The evolution of the sources is traced by the overall temperature (measured by the far-infrared color), which increases systematically with the decreasing ratio of envelope mass to stellar mass. The observed anticorrelation of near-infrared and radio continuum emission suggests that the erosion of the envelope proceeds from the inside out. Conventional tracers of the evolution of low-mass objects do not change much over this narrow age range.