As a non-habitual resident in Portugal or Spain, it seems that the dividends are tax free if they come from a foreign source but you still have to pay taxes in the country of origin [1].
So maybe if you set up your company in another tax friendly country, you would be able to pay your corporate tax and taxes on your dividends there.
[1]: http://www.newco.pro/blog/en/portugal-or-spain-two-tax-regim...