Future electric grids will face severe uncertainties with the unprecedented penetration of renewable energy sources, which may cause problems in grid exploitation. It is essential to evaluate the uncertainty of system performance in this grid; therefore, traditional exploitation methods may not be suitable for distributions grid such as multi-carrier microgrids when considering the electricity and gas grid constraints. This paper proposes an effective method for simultaneously optimizing different types of energy infrastructure in an environment with various uncertainties while considering grid constraints. To address the multi-energy synergy supply optimization problem in the micro energy grid, a coordinated two-stage programming approach is also suggested. A day-ahead and real-time phases are separated in the scheduling cycle to overcome the effects of the unpredictability of wind energy and solar power. The findings of the day-ahead forecast are then taken into account as uncertain variables for the higher-layer model. The demand response programming model and the energy storage revision model are lower-layer models considering the actual value as the realization of uncertain variables. The competitive swarm optimization algorithm is used to solve the problem mentioned above The Cumulative search optimization (CSO) uses global and local systems in particle swarm optimization and adopts a novel learning mechanism for creating competition between particle pairs. Comprehensive numeric examinations show that convergence speed and precision are critical, especially in solving large-scale problems. Therefore, we use chaos theory to improve its performance. Finally, the proposed method is tested and discussed on a system. The results showed that: (1) power-to-gas could convert extra electricity into natural gas; (2) the proposed two-stage optimization model and algorithm achieved different energy optimizations; (3) price-based demand response (DR) can level the energy load curve and maximize multi energy grid (MEG) revenue by using complementary specifications of energy price; and (4) the micro energy grid could communicate with the high-degree energy grid in order to gain more economic benefits. Accordingly, the incentive-based demand response (IBDR) output is reduced. The electricity and heating provided by convention gas turbine (CGT) is increased, which is fed to upper power grid (UPG) and upper heating grid (UHG). Since MEG’s purchasing power from UPG during the peak period generates more total revenue than island operations. Based on the obtained results, it can be seen that the proposed algorithm was about 50% faster compared to other methods and its standard deviation was about 0.0013 with different implementations, which was much better compared to other models.