We suggest a construction of Tanaka-Thomas's Vafa-Witten invariants for étale gerbes over smooth projective surface using the moduli space of μr-gerbe twisted sheaves and Higgs sheaves. Twisted sheaves and their moduli space are naturally used to study the period-index theorem for the corresponding μr-gerbe in the Brauer group of the surface. Deformation and obstruction theory of twisted sheaves and Higgs sheaves behave like general sheaves and Higgs sheaves. We define the virtual fundamental class for the moduli space and the twisted Vafa-Witten invariants using virtual localization and Behrend function techniques. As an application, for the Langlands dual group SU(r)/Zr of SU(r) we define the SU(r)/Zr-Vafa-Witten invariants. We prove the S-duality conjecture of Vafa-Witten for the projective plane in the case of rank two and for K3 surface in the case of prime ranks.