Some people use 'awhile' as an adverb, meaning 'for a period of time', as in 'Wait awhile'. Others, myself included, say 'Wait a while', in the same way as you'd say 'Wait a moment' or 'Wait a minute'. It is not necessary to use the one-word form here. It's fine to say 'Wait a while'.
'A while', as separate words, is the article 'a' followed by the noun 'while'. For example: 'I stayed there for a while'. Although some people do say 'I stayed there for awhile', this is as incorrect as saying 'I stayed there for atime' or 'I stayed there for aminute'. You need to follow 'for' with a noun, not an adverb.
It is not accurate to say that they are interchangeable.
Confused? You don't have to be.
Here's my advice, for what it's worth:
Never say 'awhile'. It is a completely unnecessary word. Always use 'a while' and you will always be correct.