It is for such reasons that ancient cultures used to conduct special prayers and moving rituals when they moved into a new place. There are special mantra chanting which are also conducted to clear such stuck energies. Smudging is probably the easiest of all remedies and can be easily conducted while praying and sending positive energy and intention- clearing any stuck spatial energy patterns.
Of course, here we are speaking about negative energies. Since they are the ones which bring about discontent and discomfort. But positive energies can also continue to be there long after those people/instances! For e.g. I still remember the beautiful trek in Assisi to St. Francis monastery, where St. Francis used to live and pray for years on end. Even as you step into the town of Assisi (in Italy), you feel a kind of calm pleasantness. Even the “energy non-believers” commented on how suddenly everything seemed more calm and serene! That is why visiting temples and other sacred places has such a profound helpful, healing and calming effect on people.
The other energy that tends to impact the spatial energy of a building/house is how and where it is constructed. For e.g. you may have heard that it is not advisable to sleep with your head in the north direction, since the north pole of our body’s magnetic field will be in constant opposition to earth’s magnetic north pole and over time, this could manifest as ailments and other issues in the body. Also, some people feel more sense of unease when they are in basements, particularly where it is a few levels beneath surface ground. That is why ancient folks (and even some wise modern day builders) use principles of Vaastu (ancient Indian science) and other such spatial energy considerations while choosing new plots for community planning and building construction.
Just want to mention an important side-point: all electric appliances will have an associated magnetic field (since it is electro-magnetic energy). When electricity is passing thru the wires, magnetic energy is also present at right angles to it, so in an outward vector! Because of this it is advisable to ensure that all major electric appliances (including television) are placed much away from your place of rest and relaxation. So not having heavy electric appliances like television in your bedroom will help in creating a soothing ambience and allow your body to relax better.