a.m. and p.m. are abbreviations of temporal relationships:
ante meridiem (before noon): a.m. (OK)
post meridiem (after noon): p.m. (OK)
If A.M. and P.M. were proper names, e.g. United States / U.S., then they'd be acceptable, but since *Ante Meridiem and *Post Meridiem are not proper names, they shouldn't be capitalized.
A.M. (Not OK)
P.M. (Not OK)
Lastly, without the periods, AM, PM, am, pm are all incorrect. All the Aa's and the Pp's and the Mm's stand for a word, and if you're going to abbreviate a word, you need to use a period, e.g., abbreviate => abbrev.; ante meridiem => a.m. and post meridiem => p.m.