For the digital input, the configuration with which I connected the TVS SM24-02HTG is for use in bidiretional mode as recommended in its datasheet. However, I have replaced the TVS with an SZSMF26AT1G which has SOD-123 package.
An alternative is to use bidirectional optos, where the reverse led provides natural clamping, and you do not care about the polarity.
You need just a single series R then.
If you get gain-banded optos, you can use the gain to set a switching threshold,
Small package, gain defined optos (100-300) in AC are parts like HT-3H4-
BTP1-G and AT3H4
B-CuH-S from lcsc
For output stages, you can add an active current limit, with a transistor and resistor, that protects against short circuits.
For 24V outputs I'd select a device rated well above the 30V of your PMOS part.
80V is a common rating for opto parts, so that seems a practical ballpark for voltage rating.