This paper addresses the optimal control and selection of gaits in a class of dynamic locomotion systems that exhibit group symmetries. We study near-optimal gaits for an underwater eel-like robot, though the tools and analysis can be applied more broadly to a large family of nonlinear control systems with drift. The approximate solutions to the optimal control problem are found using a truncated basis of cyclic input functions. This generates feasible paths that approach the optimal one as the number of basis functions is increased. We describe an algorithm to obtain numerical solutions to this problem and present simulation results that demonstrate the types of solutions that can be achieved. Comparisons are made with experimental data using the REEL II robot platform.