Theoretically, you will get the same amount of energy out of putting hydrogen and oxygen through a fuel cell as it takes to produce them by electrolysis, and you can reach this result by adding up all the enthalpies of formation involved using Hess' Law and realizing that the fuel cell is just the reverse process of electrolysis.
It is therefore impossible to have a net energy gain by this process as it would violate the conservation of energy.
It is, however possible to lose energy during this process and in the real world, energy is lost during both steps.
- Takes a net input of energy to produce hydrogen and oxygen
- Much of the electricity added is wasted to produce heat due to electrical resistance and overpotential losses.
Current large scale electrolysis systems have efficiencies of at best ~70% 
- Storage of the gases is also energetically wasteful as they need to be compressed. (or perhaps the hydrogen stored as a metal hydride)
- Produces a net output of energy by consuming hydrogen and oxygen.
- Suffers from the same types of electrical losses as the electrolysis process, resulting in sub-100% conversion efficiency
Fuel cells are still useful devices as they can produce electricity without combustion, without the limitation of sunlight, etc., but they require a source of hydrogen.
Most hydrogen is produced from natural gas because producing it by electrolysis is so inefficient and requires energy from somewhere else.
In the future electrolysis combined with fuel cells might become useful for temporarily storing electricity for load balancing solar panels or other green power sources, and there are some projects using hydrogen generation for grid storage purposes where excess power is stored as hydrogen in underground reservoirs, but they use hydrogen combustion generators to get electricity back as fuel cell technology has not advanced sufficiently. Example in Newfoundland