This study addresses the problem of optimal operation and functioning of lithium-ion batteries in direct current (DC) microgrids with photovoltaic generators, in both urban and rural settings, under an approach that considers three mathematical models as objective functions: reduction of operational costs, reduction of power losses associated with energy transport, and reduction of CO 2 emissions produced by conventional generators. After defining the objective functions, six optimization algorithms are integrated as solution methodologies: Equilibrium Optimizer (EO), Salp Swarm Algorithm (SSA), Particle Swarm Optimization (PSO), Sine and Cosine Algorithm (SCA), Black Hole Optimizer (BHO), and the Generalized Normal Distribution Optimizer (GNDO) algorithm. These methodologies are used to determine the hourly power flow through successive approximations, thus evaluating each of the objective functions with the system's constraints in order to achieve reductions of each objective function and thereby confirm the quality of the solutions applied to the problem under analysis. Where, for the urban case of Medell & iacute;n, the optimization achieved minimum reductions of 0.163% in fixed costs, 1.436% in variable costs, 7.160% in power losses, and 0.165% in CO 2 emissions. In the rural case of Capurgan & aacute;, the results showed minimum reductions of 0.095% in energy costs and 10.938% in power losses. These numerical results confirm the effectiveness of the applied optimization algorithms in reducing operational costs, power losses, and emissions, thereby validating the quality of the solutions for the analyzed problem.