Aiming at the power quality problems of integrated energy distribution network, the grid optimization measures are adopted for optimization. Firstly, considering the four indices of voltage deviation, harmonic voltage, voltage fluctuation and three-phase imbalance, the analytic hierarchy process (AHP) is used to establish the power quality evaluation system of integrated energy distribution network, in which the subjective weight of each index of the evaluation system is determined based on fuzzy analytic hierarchy process. Then, taking the comprehensive energy distribution network optimization scheme as the control variable, considering the complementary operation of various energy forms in the system, taking the maximization of distribution network power quality evaluation index as the objective function, and taking into account the necessary constraints such as distribution network topology constraints, node voltage constraints and network radial constraints, the distribution network reconfiguration optimization model is established. The operation principle of the stochastic forest algorithm is analyzed, and the model solution process is designed based on the stochastic forest algorithm. The simulation algorithm analysis shows that the established model can improve the power quality of distribution network, and verifies the correctness and effectiveness of the model.