I know both are related to safety or peace of mind but is there a certain context in which one is better to use than the other?
They have quite a different meaning.
Think of 安心 as "relief" or "peace of mind" while 安全 is more "safety" or "security".
Example of use of 安心:
I was relieved to hear that he was safe.
Example of use of 安全:
For your safety, please fasten your seat belt.
This is the typical thing you hear when you hop on a taxi for example (this is not a literal translation, but the point here is to stress the meaning of 安全).