No, setting up offshore is not illegal. However, withholding information about your offshore investments is illegal in some countries.
An offshore jurisdiction should be perceived as just another foreign country, but with certain advantages. These can take the form of banking secrecy laws, advantages in forming companies for international trade through tax treaties, no interest tax, no inheritance taxes, no capital gains tax, no individual tax, and many others.
Depending on your personal needs or preferences, there will normally be one or more offshore jurisdictions offering the services you are looking for.