First, I am not licensed to practice law in California so I would strongly urge you to consult directly (i.e., not online in a forum like this) with an attorney licensed in California.
That being said, you should not be subject to California state income tax as a result of selling your stock. Income from the sale of stock is, generally speaking, sourced to the residence of the seller. In your case, since you do not live in California, the gain from the sale of your stock would not be sourced to California and you should therefore not be subject to tax on that gain.
You should also not be subject to federal tax on the gain because, again, gains from trading in stock for your own account is sourced to your place of residence.
In order to prevent the seller from withholding 30% of the proceeds as US withholding tax, you should provide the seller with a Form W8BEN to prove your nonresident alien status.
Transferring the money to another US company you own only makes sense if you need to use that money for the company's business. If you transfer it to that company for holding and then later on transfer it out to yourself, you risk having the money treated as a dividend payment, which could be subject to US 30% withholding tax.
Also, if the company whose stock you're selling has interests in real estate, you should consult with a competent US tax advisor with expertise in foreign/international tax matters because the gain on the sale of the stock in those circumstances may be treated as US-source income rather than as foreign source income.
My answer does not constitute legal advice and may not be relied upon by anyone for any purpose and does not constitute an attorney/client relationship or an offer to form such a relationship. This disclaimer is intended to be fully compliant with the requirements of Treasury Department Circular 230 and the terms thereof are fully incorporated by reference. If you wish to consult with me please contact me at dwatchley@newyorktaxcounsel or visit my website at www.newyorktaxcounsel.com
Provided that you have a gain, you are required to pay Federal income tax and State income tax, if there is one in California (and for this you need to contact a tax attorney in CA). From a Federal perspective, you said you held shares for more than 1 year (a.k.a. long-term-capital-gain) so you will be subject to a special tax rate depending on the tax bracket you fall in based on your ordinary income. Please consider also that there may be the possibility of the application of a Tax Treaty. As for the last tax planning option you suggest, I would encourage you to work closely with an international tax attorney and CPA. Good luck!
This reply is offered for educational purpose only. You should seek the advice of an attorney. The response given is not intended to create, nor does it create an ongoing duty to respond to questions. The response does not form an attorney-client relationship, nor is it intended to be anything other than an educated opinion of the author. It should not be relied upon as legal advice. The response given is based upon the limited facts provided by the undisclosed individual asking the question. To the extent additional or different facts exist, the response might possibly change. Attorney is licensed to practice law only in the State of New York. Responses are based solely on New York Law unless stated otherwise. Pursuant to Internal Revenue Service guidance, be advised that any federal tax advice contained in this written or electronic communication is not intended or written to be used and it cannot be used by any person or entity for the purpose of (i) avoiding any tax penalties that may be imposed by the Internal Revenue Service or any other U.S. Federal taxing authority or agency or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.