Your challenge is pretty much exactly what the title says: prevent the Kingdom of Tungning from getting annexed by the Qing dynasty or another power for as long as you can.
Have it allied with the Portuguese, I guess? You'd still have to deal with the Chinese rites controversy as far as the then-relatively new Chinese immigrant community is concerned.