"Is the "vision range" of the building also the range where attack is possible?"
Yes, you can attack what you can see. If a scout walks by a military building, you can also attack (temporarily) that building although it was not visible before.
Soldiers are available in a certain radius around the attacked building (25 fields IIRC). All military buildings inside this area can send soldiers, independent of whether the building has a vision range large enough to see the building or not. It is only important that the building you want to attack is visible (not covered by fog of war) by another building, a scout, or a ship.
"Or is there anything I can do to get a better defense?"
The trick is to be able to mobilize more units than the enemy in the area where the battle takes place.
Since only 1vs1 battles take place, having hundreds of soldiers when the enemy attacks with few soldiers is not the best way, I think. It is more important that your soldiers are trained well. When your enemy attacks with dozens of rookies, your soldiers can kill them one by one, then retreat in a building to heal themselves. I once had a situation where two fully trained soldiers killed a whole untrained army (30 soldiers) of the computerplayer.