.m4a is an MP4 file that is renamed so that iTunes knows it is 'safe' to store ID3 tags in it. These tags are stored as user data in the file, so most players that support AAC in an MP4 file will play it back and just ignore the tags if they don't support them.
.aac is AAC without any container around it. Just the raw stream. You would need something like ffmpeg which can output raw streams to disk, stripping away the MP4 container from the audio data. This file format is really just a cheap-ass way to avoid paying the MPEG-4 licensing fees on the file format, and just paying the license fees for AAC itself.