You can build a house anywhere in terraria, the underground, the sky, even hell if you feel like it.
If you're making a house for an NPC house if must require:
-
Chair
-
Table
-
Door
-
Background wall
-
Surrounding wall
-
Source of light (ie torch)
For spawning (yourself) it needs:
-
Surrounding Wall
-
Background wall
-
Bed
-
Source of light (ie torch)
Be careful if you create a house where there are burrowing monsters; they can still burrow through your house and hurt you (they won't destory your house, respectively).