This paper proposes a model predictive control (MPC) approach to operate a cotton farm microgrid for the efficient utilization of renewable energy and minimal operational cost of irrigation pumps. MPC is used because of its ability to handle disturbance and real-time parameter changes. This paper establishes the MPC model of grid-connected and off-grid microgrids. The effectiveness and robustness of the MPC model are analyzed through a case study. The simulation results show that the operating cost of the MPC solution for the grid-connected microgrid is AU$12,024 lower than the strategy in the baseline; it saves 11,142 kWh of energy from the grid. Furthermore, the MPC solution exhibits excellent robustness in controlling the reservoir’s water level. After adding the rainy season disturbance data, the system saves AU$16,019.5 of total operating costs compared to the baseline. When the rainy season and high evaporation disturbance are added together, the system still saves AU$13,302 of total operating costs compared to the baseline. For islanded microgrids, existing-scale renewable energy systems using MPC can increase the utilization rate of renewable energy sources by 7% compared to the baseline, equivalent to reducing 8467 L of diesel consumption. Moreover, if the scale of the renewable energy system is quadrupled, the renewable energy source utilization rate of the MPC solution will increase to 64%, which saves 12,399 L of diesel.