Just to pin point this issue
If the Sonoff switch is slow to answer MQTT commands or seems to disconnect, try this :
When building your firmware, use the ESP8266 2.3.0 Core (instead of latest 2.4.x)
It was a drastic improvement for me.
Note: All the “official” binary firmware available here are using the 2.3.0 libraries
Aymeric