Sepnete relay and the system "freezes"? It's probably the switching of an inductive load, the contacts of the relay will provoke a spark. You say that the relay is optically separated? Unfortunately, even that may not be enough. The solution is to use this RC snubberu. It's basically a RC filter with a column of varistors, which will take care of the "extinction" of the spark, which causes problems. This filter is connected in parallel to the contacts of the relay. The module can also be used on other applications with a similar use.
4. The reduction and partial elimination of electromagnetic interference and voltage fluctuations