With further penetration of low-carbon energy conversion, microgrids (MGs) have become a necessary tool for expanding the consumption of renewable energies. In this paper, an optimal operation model for a microgrid-based multi-agent system is proposed. The goal is to save the total energy cost, which is expressed as a sum of locally observable convex functions. Therefore, improving the operational efficiency of microgrids is the key to promoting renewable energy development. This paper develops a three-layer multi-agent system model considering energy storage system and power thermal load demand response to solve the energy management problem of microgrids. In order to investigate the effect of energy storage system and demand response in microgrids, this paper designs three simulation cases, namely infrastructure case, energy storage case and demand response case. In order to prove the effectiveness of the proposed method, this paper uses the proposed method to solve three cases and compare the result with other meta-heuristic algorithms. The comparison results show that: (1) the multi-agent system model can realize the joint optimization of "resource, network, load and storage". (2) The introduction of energy storage and demand response system in microgrids can stabilize the output. Renewable energy units promote the use of renewable energy and reduce the overall operating cost of microgrids. Moreover, the results clearly demonstrate that the proposed algorithm has far better performance than other optimization methods. Also, the analysis obtained from the results shows that the cost is reduced by 1.82%. PV and WT output increased by 14.54% and 2.42%. In addition, their standard deviation decreases after ESS participation. The proposed approach is very effective through a simulation case study, which shows high potential for applications.