Detecting anomalous edges and nodes in dynamic networks is critical in various areas, such as social media, computer networks, and so on. Recent approaches leverage network embedding technique to learn how to generate node representations for normal training samples and detect anomalies deviated from normal patterns. However, most existing network embedding approaches learn deterministic node representations, which are sensitive to fluctuations of the topology and attributes due to the high flexibility and stochasticity of dynamic networks. In this paper, a stochastic neural network, named by Hierarchical Variational Graph Recurrent Autoencoder (H-VGRAE), is proposed to detect anomalies in dynamic networks by the learned robust node representations in the form of random variables. H-VGRAE is a semi-supervised model to capture normal patterns in training set by maximizing the likelihood of the adjacency matrix and node attributes via variational inference. The encoder of the H-VGRAE encodes hierarchical spatial-temporal information of topology and node attribute into multi-layer conditional random variables, and then the decoder reconstructs the dynamic network based on the latent random variables. For a new observation of the dynamic network, the reconstruction probabilities of edges and node attributes can be obtained from the trained H-VGRAE, and those with low reconstruction probabilities are declared as anomalous. Comparing with existing methods, H-VGRAE has three main advantages: 1) H-VGRAE learns robust node representations through stochasticity modeling and the extraction of multi-scale spatial-temporal features; 2) H-VGRAE can be extended to deep structure with the increase of the dynamic network scale; 3) the anomalous edge and node can be located and interpreted from the probabilistic perspective. Extensive experiments on four realworld datasets demonstrate the outperformance of H-VGRAE on anomaly detection in dynamic networks compared with state-ofthe-art competitors.