The optimal operation of microgrids is of great significance for the sake of efficient and economical management of its energy resources. The microgrid energy management system should plan to operate the microgrid while simultaneously considering the electric and thermal load. The present study proposes energy management to minimize the costs of operating an industrial microgrid. In fact, planning for energy supply is among the critical issues that distribution companies deal with daily in the competitive environment. A distribution company usually meets customer (end customer) demands by purchasing energy from a wholesale market. Given the load curtailment, distribution companies have more choices and interactions in the market. Distribution companies face the two uncertainties of load changes and price fluctuations in their daily energy supply planning which could lead to the risk of loss resulting from the distribution company's decision-making for daily energy supply planning. Thus, these companies face the challenge of maximizing profit in a risk-based environment. Therefore, the present study presents an optimal model of energy consumption in the production processes of aluminum and cement industrial units. The presented model was then used in planning the day-ahead energy of a microgrid containing these industrial units. Since the studied subject has many limitations, it would be difficult to solve it using mathematical methods. To resolve this issue then, the present study introduces a newly developed algorithm inspired by bee colonies. The proposed method seeks to significantly improve in the local and global search capabilities. In addition to confirming the validity of the proposed model, results indicate that the implementation of load-response programs and the cooperation of industrial units in the ancillary services and energy market can increase the profits of units and microgrids as well as correct the demand curve. According to the obtained results from the first and second test cases, the total profit of the aluminum unit