First Principles Calculations of the Relative Stability, Structure and Electronic Properties of Two Dimensional Metal Carbides and Nitrides