In this work, a two-level control system is used to minimize the total active power losses of an active distribution system connected to the external grid and composed of a wind turbine, two photovoltaic power sources, and two batteries. At the first control level, a model-based predictive control (MPC) is run, using non-homogeneous Markov reward models for wind power prediction and homogeneous Markov reward models for photovoltaic power. At the second level, an algorithm is run for optimal management of voltage control assets, such as voltage regulating transformers, to minimize losses. Different scenarios have been considered, highlighting the advantages of using an MPC framework. This results in an optimization process that can be influenced by different time horizons depending on whether or not the MPC is applied. The predictions allow considering a long-horizon stepwise optimization process that leads to an increasing number of variables along with the decrease of total active power losses. When the MPC is not applied, a short-horizon analysis is performed with a decrease in both the number of variables and the quality of the results. Different cases are considered in which the nominal power of a photovoltaic unit and the battery capacity are modified.