there are hundrends of examples in this forum and on the internet as well for such implementations
check: [OH2] Control ESP8266 Relay using MQTT Eventbus
(similar but not the same… you can use this as a guideline)
keep in mind that the focus of this forum is openHAB (not ESP code)
You will find many more examples of dedicated ESP forums
I will also second the recommendation to flash your ESP with some “all-in-one” framework firmware (like tasmota)