This study deals with an off-grid hybrid energy generation system composed of wind turbines, photovoltaic cells, and fuel cells to supply a specific load. The purpose is to minimize the cost of energy generation over a period of lifetime while satisfying a set of system reliability constraints in the system. The stated objective is to determine the optimal value of system components, that is, the number of wind turbines, the number and angle of photovoltaic arrays, the size of electrolyzer, hydrogen tanks, fuel cells, and DC/AC converters. The costs incorporated into this design included net present value of investment, costs of equipment, replacement and maintenance, and the costs arising from power supply interruption, all for a period of 20 years considered as the system lifetime. The data pertaining to load demand, sunlight and wind speed were considered to be known and deterministic. This design considered the failure of three main system components, namely, wind turbines, photovoltaic cells, and AC/DC converter, and incorporated a number of cost factors such as initial investment, operating and maintenance expenses, and value of lost load. The wind and solar data used in this study pertained to Ankara, Turkey. The gray wolf optimization algorithm for the first time is used to optimize such a system, and the results are compared with the ones obtained by particle swarm optimization algorithm. A new hybrid metaheuristic algorithm based on the modified-gray wolf optimization algorithm and the traditional particle swarm optimization algorithms is proposed to solve the problem. The results indicate that the gray wolf optimization algorithm achieves better optimal results in comparison to the well-known particle swarm optimization algorithm and the developed hybrid method performs better in comparison to the gray wolf optimization and particle swarm optimization algorithms for this specific optimization problem.