You cannot work for Company A in any capacity and then also sub-contract to that Company
You CAN work for Company B as a sub-contractor, you simply declare the income as untaxed income, or taxed income from another source.
The most efficient way to pay yourself as a Director is to either pay just below NI limits and then use the remaining unused tax to offset dividend tax or you pay yourself to the limit of your tax free earnings and then pay tax on everything above.
There is now also a personal dividend tax of 7.5% on all dividends paid above £2000. So for tax purposes its 19% Corporation Tax and from you a further 7.5% until you hit your marginal rate. Ltd Company is becoming a less attractive option unless you have a non-working wife who you can employ.
Remember also that HMRC get very funny indeed about interim dividends and will require a full blown account producing. I believe it is still possible to pay yourself an interest free loan provided that it is paid off inside the tax year, otherwise they expect interest to be paid.
As others have already suggested this really is one for the Accountant.