In this article, a stochastic programming approach for an optimal refinery planning problem under uncertainties is proposed. The nominal planning model is extended by means of conditional value-at-risk theory. Demand amount uncertainty and product yield fluctuation are taken into account simultaneously. The risk of customer dissatisfaction and inventory violation are considered as constraints according to the decision maker’s risk tolerance. Sample average approximation approach is employed to test the robustness of the model and determine the suitable risk aversion value. A more accurate product yield distribution based upon a Markov chain is introduced and applied in this model. A problem with such endogenous uncertainty is solved using a heuristic iterative algorithm integrating stochastic programming and simulation framework. Also, the scenario number in the stochastic programming model is determined by a statistical analysis, which is a compromise of model accuracy and problem size. At the end of this article, a comprehensive analysis is presented to illustrate the effectiveness of the proposed model.