A two-layer optimization model and an improved snake optimization algorithm (ISOA) are proposed to solve the capacity optimization problem of wind–solar–storage multi-power microgrids in the whole life cycle. In the upper optimization model, the wind–solar–storage capacity optimization model is established. It takes wind–solar power supply and storage capacity as decision variables and the construction cost of the whole life cycle as the objective function. At the lower level, the optimal scheduling model is established, considering the output characteristics of various types of power supplies and energy storage, microgrid sales, and purchases of power as constraints. At the same time, the model considers constraints, such as the power balance, the operating state of the energy storage system, the power sales and purchases, and the network fluctuations, to ensure the system operates efficiently. Taking a microgrid in South China as an application scenario, the model is solved and the optimal capacity allocation scheme of the microgrid is obtained. Meanwhile, the demand response mechanism and the influence of planning years are introduced to further optimize the configuration scheme, and the impact of different rigid–flexible load ratios and various planning horizons on microgrid capacity optimization is analyzed, respectively, by a numerical example. The comparison shows that the ISOA has better optimization performance in solving the proposed two-layer model.