This work aims to optimize the economic dispatch problem of a microgrid system in order to cover the load of a commercial building in Algeria. The analyzed microgrid system is connected to the power grid and composed of photovoltaic panels (PV), wind turbine, battery energy storage system (BESS) and diesel generator. To ensure energy balance and the flow of energy, we have implemented an energy management strategy based on Marine Predator Algorithm (MPA) and Multilayer Perceptron Neural Network (MLPNN), which guarantee an optimal economic operation of the system. First, using historical meteorological data, the power generation is forecasted a day-ahead using MLPNN, which allows the optimization of the microgrid operation. Second, the proposed strategy has been studied under three different microgrid configurations. Eventually, the performances of MPA are compared against well-known algorithms. The results indicate that the integration of the PV-BESS microgrid system significantly reduces the daily operating cost up to 34.5%. Due to the availability of wind resources in the studied area, the addition of a wind turbine to the microgrid minimizes the operating cost by 43.96% compared to the operating cost of the power grid. In the case of selling excess energy to the main power grid, the operating cost could be decreased as much as 49.33%.