In this paper, a non-isothermal two-phase flow in the cathode gas diffusion layer (GDL) of PEM fuel cell is modeled. The governing equations including energy, mass, and momentum conservation equations were solved by numerical methods. Also, the optimal values of the effective parameters such as the electrodes porosity, GDL thickness and inlet relative humidity were calculated using optimization Simulated Annealing algorithms. Optimization was done by considering the fuel cell voltage as the objective function. The results show that by increasing the relative humidity of the air, the rate of evaporation in cathode GDL and temperature distribution across the fuel cell decrease. Among the different methods of optimization, the best method for two- phase flow is the SA algorithm. Optimum porosity of the electrodes, GDL thickness and relative humidity obtained were 0.44, 0.24 mm and 99%, respectively. The fuel cell power density at optimum condition increased 6% compared to the base condition. Optimization was done by Matlab software.