Of the two, I'd say C3H7NO3 is more correct. However, this does lose bonding information (compare this format for e.g. butanoic acid and ethyl acetate). If you want something of the first form, I'd say something like H2NCH(CH2OH)CO2H just to make it slightly clearer that the hydroxymethyl is a side chain.