A formulation is developed for general relativistic ideal magnetohydrodynamics in stationary axisymmetric spacetimes. We reduce basic equations to a single second-order partial differential equation, the so-called Grad-Shafranov (GS) equation. Our formulation is most general in the sense that it is applicable even when a stationary axisymmetric spacetime is noncircular, that is, even when it is impossible to foliate a spacetime with two orthogonal families of two-surfaces. The GS equation for noncircular spacetimes is crucial for the study of relativistic stars with a toroidal magnetic field or meridional flow, such as magnetars, since the existence of a toroidal field or meridional flow violates the circularity of a spacetime. We also derive the wind equation in noncircular spacetimes, and discuss various limits of the GS equation.PACS numbers: 04.20.Cv,04.40. Dg,52.30.Cv,95.30.Qd,95.30.Sf,97.10.Cv