This paper investigates the analysis of the energy management system for a DC microgrid. The microgrid consists of a photovoltaic panel and a batteries system that is connected to the microgrid through a bidirectional power converter. The optimization problem is solved by the hybrid internal point method with the genetic algorithms method and particle swarm optimization (PSO) method, by considering forecasting demand and generation for all the elements of the microgrid. The analysis includes a comparison of energy optimization of the microgrid for solar radiation data from two areas of the world and a comparison the efficiency and effectiveness of optimization methods. The efficiency of the algorithm for energy optimization is verified and analyzed through experimental data. The results obtained show that the optimization algorithm can intelligently handle the energy flows to store the largest amount in the batteries and thus have the least amount of charge and discharge cycles for the battery and prolong the useful life.