Using "Sir/Madam" is nearly always wrong. It is probably acceptable in the salutation (if you really don't know the name of the person) but not otherwise. It is always far better to find out the name of the person and use it.
In the case of a reply to an email, you will know the person's name, since the bottom of their email will be a signoff that includes their name.
You can start your next email "Dear Mary Wright" (It is generally incorrect to use Mr or Ms with a first name.)
In the body, you almost never have to refer to the person by name. Instead, you use the pronoun "you". Note in this answer I use "you" freely. I don't need to know your name. Using "you" is not impolite.
So, in the situation that you describe:
Dear Ms Doe,
This will not be a problem anymore
Me: Thank you.
The expression "thank you" does not require a name. It should not have "sir/madam" following it. This is the correct and formal way to say thank you.
Remember "sir" is not formal, it is honorific. It is not used except by schoolchildren. You should avoid using sir or madam in formal communication.
The style you should be aiming for is "business-like". Use simple, plain direct English. Don't use honorifics. This is the expectation in formal writing.