First, attacking a prison for ‘safety’ is stupid. There are plenty of safe-enough buildings around if the writers would use their brains. Any structure made of concrete is impervious to zombies. Any industrial structure will have chain-link fences. Any military facility will have plenty of secure areas. You don’t need to go fight your way into a heavily defended compound - especially if you’re going to have to destroy it to get in.
But assuming it was the only way they could go, then the right way to do it would have been with stealth and multiple entry points. Go through the fence in three or four places, then use the tank as a big diversion while the others get close enough to start picking people off. Then once the battle has started, use the tank against tactical assets like hardened machine gun positions.
By the way, when you see soldiers marching with tanks, it’s not because the tanks are protecting the soldiers: it’s because the soldiers are protecting the tanks. Before the rise of high-speed, high performance tanks like the M1A1, tanks had to go into battle with infantry support. Otherwise they can be ridiculously easy to disable with satchel charges, fire, or other close-in techniques like grenades in the tracks or dropped down the pipe like Daryl’s stunt.
Whether Daryl’s grenade trick would have worked would depend on whether the breech of the gun was open inside. If he got lucky, the grenade could have rolled through and right into the crew cabin. If the breech was closed I’m not sure how much damage it would have done.
And those people weren’t all in cover behind the tank anyway. There was only one small-ish tank, and well over a dozen people. Perhaps two of them would have had really good cover crouching directly behind it - the rest would have been exposed.
Remember, the defenders have been head-shooting zombies for a year or two now. They’re all very good marksmen. There are at least four people with military/police training in their group, if you include Daryl’s hillbilly hunting excellence. Those people should all have been on scoped rifles, and those attackers should never have gotten within 500 feet of the prison. The Governor should never have come close to being able to kill Hershel before being drilled.
As for taking out the people behind the tank - Molotov cocktails work nicely for that. So do flanking manoevers. As soon as that tank got close enough to the compound that people could shoot around it, there was no cover left.
At least the battle ended correctly - with pretty much every attacker dead and minimal casualties to the defenders. That’s what happens when you do stupid things.