Neural Network-Based Score Estimation in Diffusion Models: Optimization and Generalization