Under the background of the shortage of traditional energy and the increasingly serious environmental problems, this paper proposes a bi-level optimization configuration method for microgrids based on stepped carbon trading and price-based demand response. The stepped carbon trading mechanism is introduced into the planning model to clarify the impact of construction processes on land carbon emissions. Simultaneously, price-based demand response during system operation is introduced, guiding users to change the electricity consumption strategies to promote the consumption of renewable energy. Then, a bi-level optimal configuration framework is constructed. The upper level is optimized to allocate the capacity of the microgrid, with the lowest annual equivalent comprehensive cost as the objective function. The lower level is optimized for microgrid operation, with the minimum sum of the microgrid operation cost and carbon emission cost as the objective function. In view of the advantages of enhanced whale optimization algorithm (E-WOA) in solving multi-dimensional feature selection problems, E-WOA and CPLEX solver are combined to solve the bi-level optimization model for the first time. Simulation results show that after introducing a stepped carbon trading mechanism, the system carbon emissions decreased by 23.09%. Considering price-based demand response under the premise of introducing a stepped carbon trading mechanism, the total cost decreased by 3.57% and the carbon emissions decreased by 19.83%.