Michael Shermer and Pat Linse published a concise outline in a recent Skeptic titled, Why People See Ghosts (and Gods, Angels, Demons, and Why They Float, Fly, and Travel Out of Their Bodies). You really have to read it so here is the link.
500 years ago demons haunted our world, and incubi and succubi tormented their victims as they lay asleep in their beds. 200 years ago spirits of the departed made bedside visits. More recently green and grey aliens began to molest people in their sleep. What is going on here? Are these mysterious visitors in our world or in our minds? They are in our minds. All experience is mediated by the brain, which consists of about a hundred billion neurons with a thousand trillion synaptic connections between them. No wonder the brain is capable of such sublime ideas as evolution and big bang cosmology. But it also means that under a variety of conditions the brain is apable of generating extraordinary experiences that are not real.