In this paper, a method of the energy management system (EMS) in multiple microgrids considering the constraints of power flow based on the three-objective optimization model is presented. The studied model specifications, the variable speed pumps in the water network as well and the storage tanks are optimally planned as flexible resources to reduce operating costs and pollution. The proposed method is implemented hierarchically through two primary and secondary control layers. At the primary control level, each microgrid performs local planning for its subscribers and energy generation resources, and their excess or unsupplied power is determined. Then, by sending this information to the central energy management system (CEMS) at the secondary level, it determines the amount of energy exchange, taking into account the limitations of power flow. Energy storage systems (ESS) are also considered to maintain the balance between power generation by renewable energy sources and consumption load. Also, the demand response (DR) program has been used to smooth the load curve and reduce operating costs. Finally, in this article, the multi-objective particle swarm optimization (MOPSO) is used to solve the proposed three-objective problem with three cost functions generation, pollution, and pump operation. Additionally, sensitivity analysis was conducted with uncertainties of 25 % and 50 % in network generation units, exploring their impact on objective functions. The proposed model has been tested on the microgrid of a 33-bus test distribution and 15-node test water system and has been investigated for different cases. The simulation results prove the effectiveness of the integration of water and power network planning in reducing the operating cost and emission of pollution in such a way that the proposed control scheme properly controls the performance of microgrids and the network in interactions with each other and has a high level of robustness, stable behavior under different conditions and high quality of the power supply. In such a way that improvements of 41.1 %, 52.2 %, and 20.4 % in the defined objective functions and the evaluation using DM, SM, and MID indices further confirms the algorithm's enhanced performance in optimizing the specified objective functions by 51 %, 11 %, and 5.22 %, respectively.