We aim to understand the rich chemical composition of AFGL 2591, a prototypical isolated high-mass star-forming region. Based on HIFI and JCMT data, the molecular abundances of species found in the protostellar envelope of AFGL 2591 were derived with the Monte Carlo radiative transfer code RATRAN, assuming either constant values or 1D stepwise radial profiles as abundance distributions. The reconstructed 1D abundances were compared with the results of time-dependent gas-grain chemical modeling, considering ages of 10,000 to 50,000 years, cosmic-ray ionization rates of 0.5 to 50 times 10^-16 s^-1, uniformly-sized 0.1-1 micron dust grains, a dust/gas ratio of 1%, and several sets of initial molecular abundances with C/O <1 and >1. Constant abundance models give good fits to the data for CO, CN, CS, HCO+, H2CO, N2H+, C2H, NO, OCS, OH, H2CS, O, C, C+, and CH. Models with an abundance jump at 100 K give good fits to the data for NH3, SO, SO2, H2S, H2O, HCl, and CH3OH. For HCN and HNC, the best models have an abundance jump at 230 K. The time-dependent chemical model can accurately explain abundance profiles of 15 out of these 24 species. The jump-like radial profiles for key species like HCO+, NH3, and H2O are consistent with the outcome of the time-dependent chemical modeling. The best-fit model has a chemical age of 10-50 kyr, a solar C/O ratio of 0.44, and a cosmic-ray ionization rate of 5 x 10^-17 s^-1; grain properties and external UV intensity do not affect the calculated chemical structure much. We thus demonstrate that simple constant or jump-like abundance profiles agree with time-dependent chemical modeling for most key C-, O-, N-, and S-bearing molecules. The main exceptions are species with very few observed transitions (C, O, C+, and CH), with a poorly established chemical network (HCl, H2S) or whose chemistry is strongly affected by surface processes (CH3OH).