Aiming at the cooperative optimization problem of economy and environmental protection of the traditional microgrid, including micro gas turbine and diesel engine, carbon capture and storage, and a power to gas system which can consume wind and light and deal with carbon dioxide, is introduced, and three optimization scheduling models of the microgrid based on improved BBO algorithm are proposed. Firstly, a micro-grid with a power to gas system is constructed, and an optimal scheduling model is built which takes into account the system operation cost, environmental governance cost and comprehensive economic benefit. Secondly, the ecological expansion operation is introduced, an improved BBO algorithm is explored by improving the mobility model, and its convergence is derived in detail. Finally, the microgrid system energy optimization scheduling is realized based on the improved BBO algorithm. Compared with the scheduling model that only considers the operation cost or pollution gas control cost, the total cost of the comprehensive economic benefit scheduling model is reduced by 15.5% and 5.5%, respectively, which reflects the reasonableness of the scheduling model and the effectiveness of the improved algorithm.