The diffraction of TE- and TM-polarized plane waves by planar gratings is numerically analyzed using a combined FEM/MoM algorithm based on the generalized network formulation. The interior region, treated using the FEM, is truncated to a single unit cell with the introduction of an exact periodic boundary condition, which is enforced as a natural boundary condition. By employing the finite element method to compute the fields within the periodic structure, gratings of arbitrary cross section and material composition can be efficiently modeled.