A simultaneously transmitting and reflecting surface (STARS) aided terahertz (THz) communication system is proposed. A novel power consumption model depending on the type and the resolution of individual elements is proposed for the STARS. Then, the system energy efficiency (EE) and spectral efficiency (SE) are maximized in both narrowband and wideband THz systems. 1) For the narrowband system, an iterative algorithm based on penalty dual decomposition is proposed to jointly optimize the hybrid beamforming at the base station (BS) and the independent phase-shift coefficients at the STARS. The proposed algorithm is then extended to the coupled phase-shift STARS. 2) For the wideband system, to eliminate the beam split effect, a time-delay (TD) network implemented by the true-time-delayers is applied in the hybrid beamforming structure. An iterative algorithm based on the quasi-Newton method is proposed to design the coefficients of the TD network. Finally, our numerical results reveal that i) there is a slight performance loss of EE and SE caused by coupled phase shifts of the STARS in both narrowband and wideband systems, and ii) the conventional hybrid beamforming achieved close performance of EE and SE to the full-digital one in the narrowband system, but not in the wideband system where the TD-based hybrid beamforming is more efficient.