Help needed for Arduino control system- serial + PWM


A clueless chemical engineer here looking for some help. I am trying to use an Arduino Mega to control an experiment and need to have the following functionality: monitor for incoming serial commands (from ML algorithm in MATLAB), control two devices via PWM, control 18 devices on/off via relays and control 3 devices in a pulsed manner (on for x seconds, off for y seconds). Problem is I need all of this to happen simultaneously. Is there any way to do this? Thank you in advance for your guidance.

These links should get you started
Serial Input Basics - simple reliable ways to receive data.
Several Things at a Time
Planning and Implementing a Program