This document describes a study on optimal power flow (OPF) in an islanded microgrid, focusing on a hybrid power system comprising wind, solar, and diesel energy sources under stochastic conditions. It formulates a control model that aims to minimize energy production costs while accounting for uncertainties such as load changes and the random failures of diesel generators. Numerical examples demonstrate the effectiveness of the proposed model using the Hamilton-Jacobi-Bellman equation to ensure power flow balance amidst these uncertainties.