Periodic orbits of continuous and discontinuous piecewise linear differential systems via first integrals