Two-dimensional van der Waals heterojunctions consisted of p–n-type semiconductors have been rapidly developed owing to their built-in electric field which can facilitate the separation of photogenerated electron–hole pairs and properties like current rectification and negative differential transconductance. Benefitting from these advantages, we have prepared an air-stable multifunctional p-tellurium (Te)/n-MoS2 heterostructure working both as a self-driven broadband photodetector and as an optically switchable complementary metal-oxide-semiconductor inverter. For photodetection, this device exhibits wavelength-modulated positive/negative optical response with large responsivity (1.51 A/W at 520 nm and 642.92 mA/W at 1550 nm, Vds = 0 V) and fast response speed, showcasing its prospects for optical encoding communication. Moreover, the device has been demonstrated to function as an inverter that will be shut down by illumination. Our multifunctional device possesses the compactness of integrated modules, widens the application scope of Te-based heterojunctions, and provides a reference for the application of Te-based devices in the field of integrated circuits.