We are in front of an epochal change in the power distribution and generation scenario. The increasing request of energy, the energy dependency of several countries from few foreign nations endowed with oilfield or gas field, and, on the other hand, the climate change and environmental issues are the main explanation of the recent development and spread of renewable distributed energy generation technologies. Examples of them are photovoltaic panels, wind turbines or geothermal, biomass, or hydroelectric. They are called small-size generators, or micro-generator, since the amount of power they can produce is significantly lower than the one produced by the huge, classical power plants. These distributed energy resources (DERs) are located close to where electricity is used, in the distribution network. Furthermore, they are connected to the electrical grid via electronic interfaces, the inverters, that could allow us to control the power injected into the grid. This thesis is focused on the study of some crucial aspects of this new energetic scenario: 1. Modeling: we recall the classical models and a recent linearized one of the power systems, that will be very useful for the design and the analysis of our algorithms. 2. Optimal Reactive Power Flow (OPRF) problem: in this part we recall classical and recent algorithms that deal with the reactive power regulation. In particular, we focus on the ones that solve the OPRF problem, i.e. the problem of the amount of reactive power to be injected by each micro-generators, in order to achieve “optimal” performance. We choose, as an optimality achievement, the minimization of the line losses. Finally we derive and propose our OPRF algorithm, providing formal proves of its convergence to the optimal solution. 3. Optimal Power Flow (OPF) problem: the OPF problem’s aim is to find an operating point of the power system that optimize a cost function (tipically the generation cost) satisfying the power demand and some operative constraints. After recalling the most popular algorithms that solve the OPF problem, we propose two of them. In this framework there are mainly two possible scenarios. The first is related to the “utility point of view”, where the total cost accounts for the production cost of the energy (that comes from big generation plants such as nuclear or hydro-electrical plants) and for the remuneration to be paid to the owners of DERs. In this framework, the utility imposes a behavior procedure to be followed by the producers to compute the amount of energy they have to inject into the grid to minimize the total cost. The first algorithm deal with this scenario. The second one is related to the “producer point of view”. Since the owners of the DERs are paid proportionally to the energy that they inject, they would like to maximize the power they inject, while keeping satisfied some operative constraints. The result is a game among the agents. A first treatment on this scenario is given by the second algorithm. 4. Switches monitoring for topology identification: in this part, after a literature review, we propose a algorithm for the identification of switches actions. They modify the topology of the electrical grid, whose knowledge is fundamental for monitoring, control and estimation. This algorithm works analyzing how the phasorial voltage profile vary and recognize a kind of signature left by the switches status change.