Stability of homomorphisms and derivations in $C^*$-ternary algebras