Massive evolved stars affect their local surroundings as they go through phases of intense mass-loss and eventually explode as supernovae, adding kinetic energy and freshly synthesised material to the interstellar medium. Over time, these processes affect the chemical evolution of the interstellar medium on a galactic scale. I will here present my PhD research, which probed the death throes of massive stars at various stages. First, CO observations were used to study the circumstellar environment of a massive star, the yellow hypergiant IRAS 17163-3907. Observations with APEX and ALMA ACA reveal a complex environment with several distinct components: a fast recent stellar wind of 100 km/s, a clumpy CO ring which appears to be a torus ejected by the star several thousand years ago, and a unidirectional bright spur extending from the star to the clumpy ring. These asymmetries are not seen in infrared dust observations, and demonstrate the complexity of massive evolved stars and the need for high resolution molecular observations to understand them. Next, observations of CO lines in the supernova remnant Cassiopeia A were used to study the effect of the reverse shock on supernova ejecta. A large column density of warm CO was found, which has most likely re-formed after the passage of the reverse shock. The high temperature and density implies that thermal conduction by electrons may be an important process for the evolution of dense ejecta knots, with implications for the survival of supernova dust. Finally, the contribution of massive stars to galactic chemical enrichment was investigated indirectly with measurements of isotopic ratios in a molecular absorber at z=0.68 towards B0218-211. The ratios at z=0.68 were found to be very different from those in the solar neighborhood, but similar to the ratios found in another absorber at z=0.89 and in starburst galaxies. The interpretation of these ratios is as a signature of enrichment mainly by massive stars.