A photocurable and thermosetting coating composition which can be diluted with water is disclosed. This composition comprises a photopolymerizable resin having a number-average molecular weight in the range of from 500 to 50,000 and containing an aprotic ammonium salt-containing moiety in a proportion of from 0.2 to 4.0 mols per kilogram of the resin, a photopolymerization initiator, a thermosetting component, and a diluent. The photopolymerizable resin is obtained by the reaction of a polymer possessing a tertiary amino group with a monocarboxylic acid and a monoepoxy compound either or both thereof possessing a polymerizable unsaturated double bond. As the thermosetting component, at least one member selected from the group consisting of amino resins, cyclocarbonate compounds, blocked isocyanate compounds, and epoxy resins is used. A tack-free coating film is obtained by applying this composition to a printed circuit board and drying the applied layer of the composition. A delicate resist pattern can be formed by exposing the coating film to an actinic radiation and developing the unexposed areas of the coating film with water or a dilute aqueous acid solution. By thermally curing the patterned resist film, a solder resist film excelling in various properties expected of a solder resist is obtained.