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 安全).
An easy way to remember this is that 安心 has the kanji for safe and heart, so as Tommy said, peace of mind your heart is at ease.
安全 has the kanji for safe and complete/full/all, so you can think 'all is safe', which leans more towards security and safeness.