This paper focuses on modeling, sizing and cost analysis of a photovoltaic (PV)/wind generator (WG)/diesel hybrid system considering two storage devices: battery and fuel cell (FC). In comparison with the traditional PV/WG/diesel/battery systems in which battery banks are used as the storage system, PV/WG/diesel/FC systems combine fuel cell, electrolyzer and hydrogen storage tanks as the energy storage system. For cost analysis, a mathematical model is introduced for each system’s component and then, in order to satisfy the load demand in the most cost-effective way, one discrete version of harmony search (HS) algorithm is developed to optimally size the systems components. As an efficient search method, HS has simple concept, is easy to implement, can escape local optima by use of probabilistic mechanisms, and only needs one initial solution to start its search. Two robust optimization techniques are used for comparison and validation purposes, the simulated annealing (SA) algorithm and HOMER software. In addition the economic aspects of PV/WG/diesel/FC system are compared with those of the traditional PV/WG/diesel/battery system and break down of the total annual cost of the systems is given in detail.