My Arduino freezes if power removed from the HMI
It seems that Software Serial is waiting for "high" on RX 

Only a hardware solution comes to my mind 







simulate this circuit &ndash; Schematic created using CircuitLab

This way Arduino RX will be released on HMI power loss

Later edit

You can also use the watchdog timer to unfreeze your code when unresponsive. It will reset the Arduino if wdt_reset() is not called in a given amount of time and you can make the cleaning you need before using Software Serial again. Here is a useful tutorial.