This paper proposes an improved Bacterial Foraging Optimization for economically optimal dispatching of the microgrid. Three optimized steps are presented to solve the slow convergence, poor precision, and low efficiency of traditional Bacterial Foraging Optimization. First, the self-adaptive step size equation in the chemotaxis process is present, and the particle swarm velocity equation is used to improve the convergence speed and precision of the algorithm. Second, the crisscross algorithm is used to enrich the replication population and improve the global search performance of the algorithm in the replication process. Finally, the dynamic probability and sine-cosine algorithm are used to solve the problem of easy loss of high-quality individuals in dispersal. Quantitative analysis and experiments demonstrated the superiority of the algorithm in the benchmark function. In addition, this study built a multi-objective microgrid dynamic economic dispatch model and dealt with the uncertainty of wind and solar using the Monte Carlo method in the model. Experiments show that this model can effectively reduce the operating cost of the microgrid, improve economic benefits, and reduce environmental pollution. The economic cost is reduced by 3.79% compared to the widely used PSO, and the economic cost is reduced by 5.23% compared to the traditional BFO.