This paper deals with the optimal design of a stand-alone hybrid system composed of wind turbines, solar photovoltaic panels and batteries. To compensate for a possible lack of energy from these sources, an auxiliary fuel generator uarantees to meet the demand in every case but its use induces important costs. We have chosen a two-stage robust approach to take account of the stochastic behavior of the solar and wind energy production and also of the demand. We seek to determine the optimal system, i.e. the one that generates a minimum total cost when the worst case scenario relating to this system occurs. We propose a constraint generation algorithm and prove that each sub-problem (the recourse problem) can be reformulated by a mixed-integer linear program and hence solved by a standard solver. We also propose in this paper a polynomial dynamic programming algorithm for the recourse problem and show that, in some cases, this algorithm is much more efficient than mixed-integer linear programming. Finally, we report computational experiments on instances constructed from real data, that show the efficiency of the proposed constraint generation algorithm.