Several years back when I first begun working in the healthcare industry I had a situation where I billed an insurance company and the insurance company overpaid our company. I asked a posek and was told I can rely on the heter of טעות עכו״ם and therefore can keep the money, and so I did for that case and subsequent situations.
Recently a friend of mine asked the same shaylo to another posek and was told this is מותר so long as the money was an ACH to your account by the company. However if the money was sent in the form of a check you cannot then go deposit it into your account because of גזל.
Can I continue to rely on the first posek? If not at this point it would be very difficult to retrace this money so how would I do tshuva for these situations?
You can rely on the first posek regarding anything that was already done, however for the future when they overpay, let them know. It happens to be that sometimes it is too much of a bother to take the money back, and might say just forget about it