This is one I don't think I've ever seen addressed anywhere, although even good writers often get the usage wrong. That's mostly because writers tend to use one form or the other for all usages.
The common usage is that 'awhile' is used when the usage is as an adverb of time (other words that are, or have one of their meanings as, adverbs of time are words like - then, now, already, just, since, and many more). So:
She nagged awhile, so I told her we could talk about our relationship and that I'd pencil it in on my calendar for three years from Wednesday.
But when used as a noun phrase acting as the object of a preposition it is written 'a while.' So:
She wanted to talk about our relationship, and I told her that maybe we could after a while; I turned my attention back to the game.