Amidst the increasing complexity of microgrid optimization, characterized by numerous decision variables and intricate non-linear relationships, there is a pressing need for highly efficient algorithms. This study introduces a tailored Mixed Integer Nonlinear Programming (MINLP) model that optimizes the charging and discharging schedules of electric vehicles (EVs) and energy storage systems (ESS) while incorporating Distributed Flexible AC Transmission System (D-FACTS) devices. To address these challenges, a novel approach based on the Large-Scale Two-Population Algorithm (LSTPA) is proposed. The model's effectiveness was evaluated using a 33-node microgrid, where the proposed method achieved a total purchased energy of 1.2 MWh, a voltage deviation of 0.0357 p.u, and a CPU time of 551 s, outperforming traditional methods like NSGA-II, PSO, and JAYA. Additionally, in a 69-node microgrid, the approach resulted in a total purchased energy of 0.3 MWh and a voltage deviation of 0.0078 p.u. These results demonstrate the superior performance of the proposed method in terms of energy efficiency, voltage stability, and computational time, advancing the efficiency of microgrid management.