What is difference between analog and digital input and output, and when should i use anlog or digital (input or output)?
You will use digital pin modes when dealing with signals that are either "on" or "off", such as an LED, a switch, or another digital IC. 

Analog inputs are used when you want to read the voltage potential of something. This is typically used to read analog sensors. Analog outputs are not really analog at all on the Arduino. Instead, the Arduino uses something called PWM to create a pseudo-analog signal.

You can read more about analog and digital here:
https://learn.sparkfun.com/tutorials/analog-vs-digital