An energy management system based on the rolling horizon control approach has been proposed for the grid-connected dynamic and stochastic microgrid of a university campus in Malta. The aims of the study are to minimize the fuel cost of the diesel generator, minimize the cost of power transfer between the main grid and the micro grid, and minimize the cost of deterioration of the battery to be able to provide optimum economic operation. Since uncertainty in renewable energy sources and load is inevitable, rolling horizon control in the stochastic framework is used to manage uncertainties in the energy management system problem. Both the deterministic and stochastic processes were studied to approve the effectiveness of the algorithm. Also, the results are compared with the Myopic and Mixed Integer Linear Programming algorithms. The results show that the life span of the battery and the associated economic savings are correlated with the SOC values. (c) 2021 The Author(s). Published by Elsevier Ltd.