After tomorrow I'll be away for a while...

Are these two sentences correct : “After tomorrow I’ll be away for a while, because I’m going to Spain. I’ll visit you when I’m back.”

Although these sound on the face of it like a total mish-mash of tenses, they do actually make sense in informal conversation.
I would prefer ‘…I’ll visit you when I come back’ as the last phrase, though.

Could you tell me how to make these sentences correct for formal usage?

How about:
I am going to Spain in two days’ time and will visit you when I return

“Two days’ time” refers to the time you will leave. It doesn’t indicate how long you will be away.
You could also say “I am going to Spain the day after tomorrow and will…”