The increase in installed capacity of renewable energy sources (RES) has a positive effect on the development of smart grids and demand side management (DSM). The reason for this is the intermittent nature of renewable energy, which is directly related to the problem of balancing the production and consumption of power within the power system. By using the DSM, the power consumption in the system comprising RES can be easier adjusted to the power production. The paper proposes an improved concept of DSM through the spatial and temporal DSM. The optimal spatial and temporal DSM aims at determining the power diagram of each individual load bus in order to achieve the optimal state in the whole system. The optimal state of the system can be quantified through the minimum daily energy losses or minimum daily operating costs. A mathematical definition of the optimal spatial and temporal DSM problem is presented as well as the algorithm for its solution. The proposed methodology has been tested by three test networks. The results confirm the overall system performance improvements that include: reduction of energy losses in the system, reduction of the operating costs and the increase of the voltage quality within the system. (C) 2017 Elsevier Ltd. All rights reserved.