I don’t believe it would be correct to use in a formal setting, ‘thank you’ would be more appropriate. Ultimately I believe it does depend on the relationship between the two people as ‘cheers’ can act as an element of covert prestige, where it will be appreciated albeit the formal setting.
Contexts where it is more commonly used are for example :
• Thanking the bus driver before you get off the bus.
• Thanking retail/shop assistants
• Amongst friends
• Thanking strangers