I think there is no way to defence tank attack. Its so powerfull unit, spec after latest update when double damage was removed from canons, boom canons and boom mines.. I hope for next update there will be some new defence unit that will make this thanks away.. In 90% my base was destroyed by tanks, and I'm starting to be frustrated because my defence dont even scrach them...
The best defense against tanks is to spread your buildings out as far as possible, and keep your tanks bouncing back and forth with your HQ in the very back. They are so flippin' slow, it usually times out before they destroy everything, if you can never seem to destroy them.
At HQ13, snipers and boom cannons are the best defenses against tanks and high level mortars may also finish them or kill their medics: they have longer range than tanks, you shall attract them in range (for instance with an isolated cannon) after having them wasting as much energy as possible with flares or "useless" artillery spent on mines.
Defending would be very hard but you should try inflicting some losses to get diamonds and Intels if you are in a Task Force.
Beach defense can be good but make sure sneaking to the back is difficult, try and pick troops landing but with some stuff to divert tanks without giving them gunboat energy for free... One isolated boom cannon on the beach is an easy target.