After much research into solar power, I was ready to make the jump to solar, but due to financial constraints I had to put it off until next season.
Anyway coming to your question, You can run anything on Solar, as long as you have the required number of watts coming from your panels and your inverter is of enough wattage. But yes, the first step would be to shift everything on UPS to solar. Since you have already done the wiring, you don't need to do any additional wiring. The only wiring required is the one coming from solar panels to MPPT charge controller and Inverter. After doing this, all you need is to plug everything that was on UPS into the inverter and you're done. The batteries connect directly to the inverter or MPPT charge controller depending on the type of setup you have.
Regarding preventing excess solar power from going back to grid. If you are using a Hybrid inverter such as Infini, this is quite easy to configure in the settings. If you are not using a hybrid inverter and you have wired the system properly, solar energy will not flow back to the grid. Because only the loads will be connected to solar and you will switch manually to solar in the day, switch back to wapda in the evening. For the 4KW APC (I am assuming it is 4KW and not 4KVA). You are talking about 4000 Watt load. You need to size the panels bigger than you load. You need at least 5000W combined from panels. If you have the budget it is better to invest in a hybrid inverter such as Infini. It also has a built in MPPT charge controller so you don't need to buy it separately. Infini will handle everything automatically, when there is sufficient power on solar, it will run everything on solar, when solar output drops, it will use wapda and solar together to handle the load, when there is no solar or wapda, it will switch to batteries. There is a 5KW Infini on the manufacturer website but it is not available as yet. So you will need a couple of 3KW Infini hybrid inverters. The load will be divided between the two inverters.
And by the way this is a bad time to go solar. The govt just imposed some duties on panels up to 32.5%. I think they will roll it back, but until then, it is better to wait and see how the situation develops.
Containers of solar panels marooned at Karachi ports - thenews.com.pk