Yes, this is possible. Several companies (VAG, BMW) have switched to AC units that are driven by electric motors. For BMW, this is part of their Efficient Dynamics strategy, where they'll switch the compressor on/off depending on engine load to optimize fuel consumption.
When the weather's not too hot, you can run the compressor intermittently without the passengers noticing anything, so they run the compressor when you're slowing down and switch it ofoff when you're accelerating. Other companies use similar strategies, BMW is just the first I could find that offered some explanation of why they switched to electric AC.
Electric AC has another advantage. On smaller engines, you can feel when an engine-driven compressor engages. That hiccup in the drivetrain can get annoying. An electric AC is unnoticable.
Running the compressor while the engine is off is another matter. The compressor draws several kW. At 5 kW you'd drain a (really big) 100 Ah battery in 12 minutes.
I don't know how feasible it is to retrofit an existing AC system to electric.