Italian prime minister Matteo Renzi is to resign after suffering a stinging defeat in a constitutional reforms referendum on which he staked his premiership.