I suspect that it is impossible to prevent stall on engine failure only by adjusting the TECS parameters in GUIDED mode (or any other flight mode that controls altitude). In these modes the FC will just try to keep a given altitude. Furthermore, the TECS parameters do not know a parameter for the best glide speed of the respective aircraft.
In a similar problem (RTL in an unpowered glider), where it is also important to maintain the best glide angle, this was achieved by using TECS_PITCH_MIN/MAX parameters very close to each other to make the glider fly with the best glide angle: What parameters to set for a glider? - #7 by Rolf
The solution should succeed with a LUA script:
As soon as the engine is idling and speed drops below a defined value, the two TECS parameters TECS_PITCH_MIN/MAX are set e.g. ± 1° than the best glide angle.
In addition, if a correctly calibrated compass and an airspeed sensor are available, the wind direction and thus the headwind component could be determined. In case of strong headwinds it is important to fly with higher speed than that of the best glide in calm conditions, so that the angles can be selected accordingly more pitch down.
Rolf