In this article, offline path planning for walking of a 2D humanoid robot with 6 Degrees of Freedom (DoF) is performed. This path planning is based on foot and hip trajectories. To make sure that walking cycle is stable, Zero Moment Point (ZMP) criterion is used. Full dynamic model of the humanoid robot in Single Support (SS) phase and Double Support (DS) phase are calculated by the use of Lagrange and Kane methods. By comparison of Lagrange and Kane methods, the dynamic model is verified. A Genetic Algorithm (GA) optimization of walking gait is proposed in which minimum energy consumption and maximum walking stability are two goal functions of this optimization. Finally the best stride length for each robot velocity is determined.