To understand the science behind ghosts you will need to get into quantum physics. Basically, Everything is composed of subatomic particles and/or energy. Even energy acts like particles at the quantum level. Matter can store energy signatures much like a tape recorder or DVD. Some people can read these signatures much like a DVD player can produce an image from stored info. What this means is that an intense event, usually a tragic death or accident, can register into the sub-atomic matter in a building or place. Under the right circumstances certain people can see, hear, or feel this recording of a prior event. In other words, they see a ghost of a past event. This type of ghost is called a residual because it doesn't really exist any more than a DVD is the ghost of the actors. Ever notice that most ghosts are tied to a structure of some type? Destroy the structure and the ghosts disappear.
Of course, this is a simplification of one type of ghost event explainable by science. Another explainable ghost creator is magnetic fields which can cause some people to have paranormal experiences. Our brains work on chemical energy that generates electrical impulses, so anything that messes with that energy will cause hallucinations. That's how LSD and 'shrooms cause people to see and hear all sorts of things. Intense magnetic fields can do the same thing. There are more, but I won't get into that here.
For more information see the works of Prof. William Roll http://en.wikipedia.org/wiki/William_G._Roll