You can use it in both of those situations, to mean either:
I'm sorry I did that.
Could you say that again?
NB not 'May you say that again? 'May' is used to ask permission with 'I' or 'we' (eg May I ask a question?)
I don't think it is especially formal. It's an expression, so you are not literally 'begging' the other person, and it's not particularly strong. I use this expression in everyday conversation.