Yes, offshore taxation is legal for businesses and individuals when it complies with the tax laws of all relevant countries.
Offshore taxation becomes illegal only when it involves:
Concealing income
Failing to report foreign assets
Creating sham entities without economic substance ...