Inspired by flight characteristics captured from live Monarch butterflies, an optimal control problem is presented while accounting the effects of low-frequency flapping and abdomen undulation. A flapping-wing aerial vehicle is modeled as an articulated rigid body, and its dynamics are developed according to Lagrangian mechanics on an abstract Lie group. This provides an elegant, global formulation of the dynamics for flapping-wing aerial vehicles, avoiding complexities and singularities associated with local coordinates. This is utilized to identify an optimal periodic motion that minimizes energy variations, and an optimal control is formulated to stabilize the periodic motion. Furthermore, the outcome of this paper can be applied to optimal control for any Lagrangian system on a Lie group with a configuration-dependent inertia.