AbstractIt's not uncommon for renewable energy sources to be regarded a good investment because of the current state of the global economy. It may be difficult to locate such resources if microgrid technologies do not meet the requirements. An elephant herding optimization (EHO) was offered as a solution to the challenges of heuristic methods. Adaptive neuro‐fuzzy inference system is used to train the EHO in this technique. The primary contribution of this essay is to optimize battery use in order to maximize battery consumption. The goal of this project is to lower operating expenses while also improving the accuracy of forecasts. Given a number of programming uncertainties depending on parameters. The proposed method is tested in MATLAB/Simulink, and the results are compared to the theoretical results. In order to ensure compatibility and competency, the new method is compared to the present cuttlefish algorithm and the whale optimization algorithm.