To answer your first question, the ghost only appears during the night, after midnight, because ghost lore of the Elizabethan time suggested that ghosts could only be out of their underworld/afterlife "place" after the witching hour -- which is midnight. It is in the dead of night that the most mysterious things happen. The first act of the play indicates that the ghost is actually out and about for quite awhile, but the hearing of the cock crowing (which indicates the "crack of dawn") sends the ghost back to his resting place until the next night. Marcellus even tells a little more of the folk lore at the end of the act when he explains that during the season of advent, the birds of morning sing all night long in order to keep the ghosts, witches, and fairies away during this blessed time of year. The ghost is not allowed to be out during the daylight hours.
As for your second question, I don't think there is any textual evidence to suggest that he is seen through a window -- in fact I think the opposite is true. When the Horatio and guards see the ghost they are all OUTSIDE the castle -- literally on guard or watch. They speak to the ghost and see that he walks away. At one point they try to stop him with a sword -- so that suggests they have close physical proximity to it. When Hamlet first sees the ghost at the end of Act 1 he follows it to a more private area of the castle, so again there is physical proximity and the scene is always staged to suggest that they are, again, on the outside of the castle. There needs to a "real" presence of the ghost in his full battle gear in order to inspire awe and wonder at the sighting of the ghost in the first place.
I think you are confusing portal with porthole. A porthole is a ship window. A portal is a large door or gateway. Hamlet watches as the Ghost "steals away "out at the portal. This appearance is as the Ghost says, to remind Hamlet of his almost blunted purpose.