Yes, you can change the locks on the house if the property is legally owned in just your name, but not if it is owned jointly with another person.
If you own the house with your former partner, then you will need their permission to change the locks and you are obliged to give them a key if they ask for one. Neither party can lock the other one out, even if they have moved elsewhere.
However, after a person has moved out of the matrimonial home, they should only come back if they reasonably need to and they should give you proper notice. As the occupier of the house, you have a right to privacy and to enjoyment of your own home but you must also accommodate fair requests to visit or inspect the property when these are made.
If you are being subjected to domestic abuse or threatening behaviour, it may be possible to obtain an injunction (non molestation order or occupation order) to restrict that person’s ability to come back to the house or to contact you except by agreed methods.
Before you move out of the family home, you should take legal advice from a specialist family lawyer to ensure that this will not adversely affect your position in a divorce.