This thesis develops optimization-based techniques for the control of distributed energy resources to provide multiple services to the power network. It is divided into three parts. The first part of this thesis focuses on the development of a framework for the efficient control of a single resource that is subject to the effect of periodic stochastic uncertainties. More specifically, resources that can be described by the general class of periodic constrained linear systems are considered and a method, based on Stochastic MPC, to control the over-time-average constraint violations is developed. Finally, the effectiveness of the control framework is tested, by means of a simulation analysis, for the case of the climate control of a building. The second part of the thesis introduces the required background for the electric power grid, energy markets, and distributed energy resources providing grid support services. First, the control problem of scheduling the operation of a set of energy resources offering multiple services to the grid is formally stated as a multi-stage uncertain optimization problem. In particular, the problem is designed so as to maximize the provision of a shared tracking service while enforcing the satisfaction of the operational constraints on both the individual resources, as well as on the hosting distribution network. Two computationally tractable approximated solution methods are then presented, which are based on robust-optimization techniques and on a linearization of the power flow equations around a general linearization point. A simulation-based analysis demonstrates the capability of the proposed framework to adapt to different levels of uncertainty acting on the overall system. Finally, a quantitative and qualitative comparison between the two approximation schemes is presented and general guidelines are given. The last part of the thesis demonstrates the practical relevance of the control framework developed in Part II. In particular, the aggregation of an electrical battery system and of an office building is considered, and two case studies are investigated. The first deals with the provision of secondary frequency control in the Swiss market, whereas the second deals with the problem of dispatching the operation of an active distribution feeder characterized by the presence of stochastic prosumers. In both cases, we show how to adapt the general framework of Part II so as to accommodate the given application. Then, we design a hierarchical multi-timescale controller in order to reliably deliver the service by coordinating the controllable resources during real-time operation. The results of both experimental campaigns demonstrate the effectiveness and robustness of the control methodology against the wide range of uncertainty involved. In fact, in both cases, high-quality tracking performance could be achieved without jeopardizing the occupants' comfort in the building nor violating the operational constraints of the battery. Finally, the results also show the benefit of combining resources with complementary technical capabilities as the building and the battery.