The critical necessity of decreasing energy consumption and environmental effects is vital in various facets of urban life, particularly in urban waste management. This research aimed to evaluate the energy flow, CExD, and Life Cycle of a composting system for Municipal Solid Waste (MSW) in Tehran province, Iran. The initial phase entailed assessing the energy flow and effectiveness of the composting system, while the subsequent phase focused on enhancing energy efficiency through the application of Data Envelopment Analysis (DEA) to determine an optimal energy consumption strategy for conserving energy and reducing environmental impacts in Tehran's MSW composting system. Over a 90-day period, the analysis of energy usage revealed an energy input and output of 417.30 GJ (8500 t MSW)−1, with 227.02 GJ (8500 t MSW)−1 linked to transportation and 190.28 GJ (8500 t MSW)−1 related to composting activities. The overall energy consumption in the composting system was determined to be 6424.77 GJ (8500 t MSW)−1. By applying DEA optimization, energy savings of 14.45 GJ (8500 t MSW)−1 were accomplished in the composting process, with a significant reduction in electricity usage contributing to these savings. The environmental impact of the energy consumption patterns identified by DEA was notably lower compared to current energy practices. The most notable decrease in impact was observed in the Photochemical Oxidation category. By following the energy usage pattern recommended by DEA, the Global Warming Potential impact reduced by 500 kg CO2 eq. per 8500 t MSW. Additionally, the optimization of energy use through DEA led to a decrease in fossil energy resource depletion by around 4 GJ (8500 t MSW)−1 in the composting process.