One of the most vital issues in electrical systems involves optimally operating microgrids (MGs) using demand-side management (DSM). A DSM program lowers utility operational costs in one sense but also needs policies that encourage financial incentives in the other. The present study formulates the optimum functioning of MGs using DSM in the form of a problem of optimization. DSM considers load shifting to be a viable option. There are operational limitations and executive limitations that affect the problem, and its objective function aims at minimizing the overall operational prices of the grid and the load-shifting prices. The major problem has been solved using an improved butterfly optimization scheme. Furthermore, the suggested technique was tested in various case studies that consider types of generation unit, load types, unit uncertainties, grid sharing, and energy costs. A comparison was made between the suggested scheme and various algorithms on the IEEE 33-bus network to demonstrate the proficiency of the suggested scheme, showing that it lowered prices by 57%.