Optimal Online Generalized Linear Regression with Stochastic Noise and Its Application to Heteroscedastic Bandits