Electron-Ion Recombination Rate Coefficients, Photoionization Cross Sections, and Ionization Fractions for Astrophysically Abundant Elements. I. Carbon and Nitrogen