Recent advancements in renewable energy technologies, alongside changes in utility infrastructure and progressive government policies, have bolstered the integration of renewable-based distributed generation units within distribution systems. This paper introduces the Energy Valley Optimizer, a novel tool designed for the strategic placement of distributed generation units and capacitor banks. This placement is crucial not only for optimizing energy loss and enhancing bus voltage stability but also for promoting sustainable energy use and reducing environmental impact over the long term. By minimizing energy loss and voltage fluctuations, the optimizer contributes to a more sustainable and resilient energy system. It achieves this through the optimal allocation of resources across various load patterns within a 24 h period and is tested on the ALG-AB-Hassi-Sida 157-bus distribution network in South Algeria. Comparative analysis with existing algorithms—such as the Liver Cancer Algorithm, Walrus Optimization Algorithm, and Zebra Optimization Algorithm—demonstrates the superior performance of the Energy Valley Optimizer. It not only enhances technical and economic efficiencies but also significantly lowers the total cost of energy over 24 years, thus supporting sustainable development goals in energy management.