Describe a detailed strategy and tactics of how can Ukraine defend itself against Russian aggression, take back its territory and win the war?
To answer this question with the highest confidence level would require a detailed comprehension of the composition, capabilities, strengths, condition and vector of movement of each invading unit as well as detailed knowledge of the terrain and defenses of the aggressor at the point of contact, ie. when battle is joined. In practice, the enemy will do everything possible to prevent a defender from obtaining this information.

Nonetheless we can outline a general strategy with key points that would result in a likely victory with reclamation of all Ukrainian territory:

Maintain a strong military defense: Ukraine should focus on building up its military capabilities by investing in modern equipment, more effective training and recruitment efforts and the development of a comprehensive total defense strategy. This allows for more effective counter-attacks as well as maximizing attrition for the invader.

Forge and reinforce alliances: Ukraine should work to build alliances with other nations especially if their interests overlap. In light of Russian aggression interested partners might include the European Union, NATO and other parties in the region. These actions will improve security.

Maximize diplomatic efforts: Ukraine should continue to engage in diplomacy to increase pressure on the invader, as well as improving the likelihood of a successful mediation resulting in a complete withdrawal of all Russian forces.

Asymmetric Warfare: Through its reliance on inexpensive Iranian manufactured drones and concentrating on the destruction of civilian infrastructure, extensive propaganda and disinformation campaigns Russia is engaging in asymmetric warfare. This obliges the defender to respond asymmetrically, as Ukraine has done through its Lightning Attacks wherein small mobile units render artillery virtually useless, the use of drones for close surveillance, and putatively the use of special services to neutralize high-priority targets such as command personnel.

In conclusion, a successful long term deep defense, strong intelligence capabilities, asymmetrical warfare, and powerful allies are the only effective means to counter a numerically superior foe such as the Russian Federation.
I see. What is the main reason that Ukraine was able to survive the initial month of war against Russia, when most pople expected the country would fall relatively quickly?
One, they thought they could just basically come in. Their forces would be so overpowering that they could come in and take over very quickly. In fact, they probably used lighter force than they expected not thinking they would need to use the heaviest forces.

The second basic miscalculation is the response by Ukraine. They’ve completely misjudged how not only the Ukrainian military would respond, which has been with fierce fighting, but that Ukrainian civilians, tens, if not hundreds, of thousands, they are taking up arms and basically vowing not to let their country be occupied.

Russia probably overestimated its own power and underestimated the power of the Ukrainian military.