Deploying distributed generators (DGs) powered by renewable energy poses a significant challenge for effective power system operation. Optimally scheduling DGs, especially photovoltaic (PV) systems and wind turbines (WTs), is critical because of the unpredictable nature of wind speed and solar radiation. These intermittencies have posed considerable challenges to power grids, including power oscillation, increased losses, and voltage instability. To overcome these challenges, the battery energy storage (BES) system supports the PV unit, while the biomass aids the WT unit, mitigating power fluctuations and boosting supply continuity. Therefore, the main innovation of this study is presenting an improved moth flame optimization algorithm (IMFO) to capture the optimal scheduling of multiple dispatchable and non-dispatchable DGs for mitigating energy loss in power grids, considering different dynamic load characteristics. The IMFO algorithm comprises a new update position expression based on a roulette wheel selection strategy as well as Gaussian barebones (GB) and quasi-opposite-based learning (QOBL) mechanisms to enhance exploitation capability, global convergence rate, and solution precision. The IMFO algorithm's success rate and effectiveness are evaluated using 23rd benchmark functions and compared with the basic MFO algorithm and other seven competitors using rigorous statistical analysis. The developed optimizer is then adopted to study the performance of the 69-bus and 118-bus distribution grids, considering deterministic and stochastic DG's optimal planning. The findings reflect the superiority of the developed algorithm against its rivals, emphasizing the influence of load types and varying generations in DG planning. Numerically, the optimal deployment of BES + PV and biomass + WT significantly maximizes the energy loss reduction percent to 68.3471 and 98.0449 for the 69-bus's commercial load type and to 54.833 and 52.0623 for the 118-bus's commercial load type, respectively, confirming the efficacy of the developed algorithm for maximizing the performance of distribution systems in diverse situations.