In this paper, trajectory generation for the 4 DOF arm of SURENA III humanoid robot with the purpose of optimizing energy and avoiding a moving obstacle is presented. For this purpose, first, kinematic equations for a seven DOF manipulator are derived. Then, using the Lagrange method, an explicit dynamics model for the arm is developed. In the next step, in order to generate the desired trajectory for the arm, two different methods are utilized. In the first method, each joint motion is presented by a quadratic polynomial. In the second one, the end effector’s path has been considered as 3 polynomial functions. Also, a known moving spherical obstacle with a linear path and constant velocity is considered in robot workspace. The main goal of optimization is to reduce the consumed energy by the arm in a movement between two known points in a specified time frame to avoid the moving obstacle. Initial and final velocities of the arm are set as zero. To this end, the optimization is carried out using Genetic Algorithm. Finally, in order to obtain the most reliable solutions for trajectory generation, many optimizations with various parameters are conducted and the results are presented and discussed.