I recently bought a second hand Giant Upland SE and to be frank, it is my first bike with multiple gears. The bike functioned normally for the first day or two. I could use all the gears. When the bike is stored indoors, the pedal and wheel work fine but once I take it out in the cold (anywhere from 0 to -30 degrees celsius), the pedals rotate freely and have no action on the wheel. Also I am not able use some gears on the rear wheel. Can anyone please help with an explanation and solution?
The pawls in your freehub are most likely getting stuck, causing them not to lock and transfer the force from the cassette to the wheel. In your case as the bike is new it is probably due to it being assembled with grease rather than a lighter oil, but the problem can also come with ageing. You will need to rebuild the freehub. This is not the easiest procedure and requires some specific tools (chain whip and freehub nut at least) so probably get your bike shop to do it.
The unusable gears on the back could be a number of things, rear derailleur limit screws, lack of cable tension, bent hanger/derailleur... If you are already taking it to a bike shop just ask them to fix it.
EDIT: Based on the additional information (-30 not 30 Celcius and secondhand), like others say the freehub is most likely frozen due to old grease and or water which has gotten inside the hub. Same advice still applies though, you will need to overhaul it and get new grease in there or just buy a new one.
If it's "cold" - as in really cold - (and not 30 deg celcius which is actually very warm) - and given your bike is new - it sounds like your freehub froze. The pawls in the freehub are frozen in their un-engaged position. So there will be no drive to the rear wheel when pedalling.
Humorously, a few years ago - I was mountain biking in the snow. It froze. And the only option was to urinate on the freehub.
You say in comments that your bike was stored outside all summer.
I'd bet you have ended up with water inside the freehub, probably emulsified with the grease/oil that is supposed to be in there.
Since oil and water don't mix, you end up with a grey/brown mucky muddy mess that is either bubbles of liquid oil floating in water, or bubbles of water floating inside grease.
Either way, when the water freezes your grease suddenly becomes more like putty and less like a lubricant.
So your answer is to clean and service the freehub and try to get all the water and contaminated grease out. If you can't get it out, then a new freehub body might be easier than disassembling.
Either way, stop storing your bike outside where it can get rained on, and where condensation might form. Even storing it under a carport or verandah is better than exposed to the raw weather.
Your freehub is frozen. This is common in places with colder temperatures. Factories often assemble less expensive hubs with whatever grease is on hand and the temperature ratings of these can vary drastically. Your freehub needs to be overhauled and have the factory grease replaced with a winter weight grease. Many automotive style lithium complex greases are good to -48C (-55F).
You absolutely should not ride your bike in this condition. You have gotten lucky with no engagement. Often, people with frozen freehubs experience partial engagement, which leads to chipped teeth/pawls/mechanisms and ultimately a destroyed freehub.