In recent years, using the renewable energy resources has attracted the attention of researchers and automobile companies, because of limited fossil fuel resources, low efficiency of internal combustion engines and their contribution to environmental pollution. By using the fuel cell systems instead of internal combustion engines overcome these problems can be partially overcome. In this regard, the present article examines a PEM fuel cell system for use in an urban vehicle. In the first part of this article, by using the real component of system, the fuel cell system components including stack, membrane humidity of air and hydrogen, air compressor, water pump and pump cooler stack have been modeled in MATLAB Simulink environment. The mentioned model can evaluate the power consumption of system and its auxiliary components and also the required water, hydrogen and air for system. At the base case and the current density of 0.7A / cm2, 14% of power productions of stack are consumed by auxiliaries units. At this current density, the overall and net system efficiencies are 48.15% and 34.3%. Also, by increasing the air stoichiometric coefficient due to increased compressor power consumption, there is not a significant increase in output voltage. In the second part of this article, the system from the point of view of the first law of thermodynamics has been optimized with objective functions of maximum output power and maximum efficiency. The results indicate that first, the model search method is the best method for optimization, second, the optimization with the aim of maximum power, pure power and system efficiency are increased by 11.9% and 4% respectively and the power consumption by auxiliary unit is reduced about 42%.