Ultrafast control of the optical response and the interlayer coupling in van der Waals materials